﻿/**********************************************************
 ●项目：Smartkernel
 ●公司：智能核心信息技术研发中心
 ●作者：曹艳白
 ●邮箱：caoyanbai@gmail.com
 ●创建：2008-08-10
**********************************************************/
using System;
using System.IO;
using System.Collections.Generic;
using Smartkernel.Attributes;
using Smartkernel.Configuration;
using Smartkernel.Data;
using Smartkernel.IO;
using Smartkernel.Xml;

namespace Smartkernel
{
    /// <summary>
    /// Core的核心配置实体
    /// </summary>
    public partial class SmartCoreEntity
    {
        #region 公有属性
        private string webServicesToken;
        /// <summary>
        /// 框架与子系统之间Web通信的令牌
        /// </summary>
        [SmartXmlMappingAttribute("WebServicesToken")]
        public string WebServicesToken
        {
            get
            {
                return this.webServicesToken;
            }
            set
            {
                this.webServicesToken = value;
            }
        }
        private string cacheServicePath;
        /// <summary>
        /// 缓存服务的路径
        /// </summary>
        [SmartXmlMappingAttribute("CacheServicePath")]
        public string CacheServicePath
        {
            get
            {
                return this.cacheServicePath;
            }
            set
            {
                this.cacheServicePath = value;
            }
        }
        private SmartDatabaseType databaseType;
        /// <summary>
        /// Core所使用的数据库类型
        /// </summary>
        [SmartXmlMappingAttribute("DatabaseType")]
        public SmartDatabaseType DatabaseType
        {
            get
            {
                return this.databaseType;
            }
            set
            {
                this.databaseType = value;
            }
        }
        private bool debug;
        /// <summary>
        /// 程序的发布状态，调试状态下不自动捕获异常
        /// </summary>
        [SmartXmlMappingAttribute("Debug")]
        public bool Debug
        {
            get
            {
                return this.debug;
            }
            set
            {
                this.debug = value;
            }
        }
        private string connectionString;
        /// <summary>
        /// Core所使用的数据库连接字符串
        /// </summary>
        [SmartXmlMappingAttribute("ConnectionString")]
        public string ConnectionString
        {
            get
            {
                return this.connectionString;
            }
            set
            {
                this.connectionString = value;
            }
        }
        private string maintenanceMails;
        /// <summary>
        /// 系统维护人员邮件。用逗号分割。
        /// </summary>
        [SmartXmlMappingAttribute("maintenanceMails")]
        public string MaintenanceMails
        {
            get
            {
                return this.maintenanceMails;
            }
            set
            {
                this.maintenanceMails = value;
            }
        }
        private string webSite;
        /// <summary>
        /// 框架Web应用程序的域
        /// </summary>
        [SmartXmlMappingAttribute("WebSite")]
        public string WebSite
        {
            get
            {
                return this.webSite;
            }
            set
            {
                this.webSite = value;
            }
        }
        private string loginPage;
        /// <summary>
        /// 框架Web应用程序的登录页
        /// </summary>
        [SmartXmlMappingAttribute("LoginPage")]
        public string LoginPage
        {
            get
            {
                return this.loginPage;
            }
            set
            {
                this.loginPage = value;
            }
        }
        private string errorPage;
        /// <summary>
        /// 框架Web应用程序的错误页
        /// </summary>
        [SmartXmlMappingAttribute("ErrorPage")]
        public string ErrorPage
        {
            get
            {
                return this.errorPage;
            }
            set
            {
                this.errorPage = value;
            }
        }
        private string defaultPage;
        /// <summary>
        /// 框架Web应用程序的默认页
        /// </summary>
        [SmartXmlMappingAttribute("DefaultPage")]
        public string DefaultPage
        {
            get
            {
                return this.defaultPage;
            }
            set
            {
                this.defaultPage = value;
            }
        }
        private string title;
        /// <summary>
        /// 系统的标题
        /// </summary>
        [SmartXmlMappingAttribute("Title")]
        public string Title
        {
            get
            {
                return this.title;
            }
            set
            {
                this.title = value;
            }
        }
        #endregion
    }
    public partial class SmartCoreEntity
    {
        #region 构造函数及字段
        private static SmartCoreEntity instance;
        /// <summary>
        /// 通过配置文件初始化的默认实例
        /// </summary>
        public static SmartCoreEntity Instance
        {
            get
            {
                return instance;
            }
        }
        /// <summary>
        /// 私有构造函数
        /// </summary>
        private SmartCoreEntity()
        {

        }
        private static string xmlPath;
        /// <summary>
        /// 静态构造函数
        /// </summary>
        static SmartCoreEntity()
        {
            if (SmartAction.IsInvokeFail(delegate { xmlPath = SmartConfiger.GetAppSettingValue<string>("ConfigFolder", true).TrimEnd(new char[] { '\\' }) + @"\SmartCoreEntity.config"; }))
            {
                xmlPath = Environment.CurrentDirectory + @"\SmartCoreEntity.config";
                if (!File.Exists(xmlPath))
                {
                    xmlPath = System.Web.HttpRuntime.AppDomainAppPath.TrimEnd('\\') + @"\ConfigFolder\SmartCoreEntity.config";
                }
            }
            //存在配置文件的时候才监视文件的变化
            if (File.Exists(xmlPath))
            {
                instance = new SmartCoreEntity();
                SmartXml.MappingXO<SmartCoreEntity>(xmlPath, SmartMappingType.Attribute, ref instance);
                SmartFileSystemWatcher.Add(xmlPath, delegate { SmartXml.MappingXO<SmartCoreEntity>(xmlPath, SmartMappingType.Attribute, ref instance); });
            }
        }
        #endregion
    }
}
